package com.css.Thread;
//存在线程不安全
//每个对象都有一把锁。sleep不会释放锁
//队列加锁，保证线程安全
public class TestSleep implements Runnable{
    private int ticketNums=10;
    public void run() {
       while (true){
           if(ticketNums<=0){
               break;
           }
           try {
               Thread.sleep(100);
           } catch (InterruptedException e) {
               e.printStackTrace();
           }
           System.out.println(Thread.currentThread().getName()+"->"+ticketNums--);
       }

    }

    public static void main(String[] args) {
        TestSleep testSleep=new TestSleep();
        new Thread(testSleep,"css").start();
        new Thread(testSleep,"dd").start();
        new Thread(testSleep,"fc").start();
    }
}

